<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>click</button>
    <script>
        // 节流：减少一段时间的触发频率，控制事件发生的频率，控制在2s发生一次

        function throttle(fun, time) {
            let now = new Date().getTime();
            return function () {
                if (new Date().getTime() - now >= time) {
                    fun();
                    now = new Date().getTime();
                }
            }
        }

        let button = document.querySelector('button')
        button.onclick = throttle(() => {
            console.log(111);
        }, 1000)

    </script>
</body>

</html>